package com.gomcarter.frameworks.redis;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * Created by daibing on 2022/8/9.
 */
@Component
@ConfigurationProperties(prefix = "yfcloud.frameworks.redis")
public class RedisProperties {
    /**
     * 是否开启缓存
     */
    private boolean cache;
    /**
     * 模式：cluster: 使用JedisCluster，连接地址列表都生效；standalone : 使用JedisPool，连接地址仅第一个生效
     */
    private String mode = "standalone";
    /**
     * 密码，类似语句中的password  redis://[:password]@host:port/db
     */
    private String password;

    /**
     * 数据库，类似语句中的db  redis://[:password]@host:port/db，注意cluster模式不支持。
     */
    private int database = 6;
    /**
     * 连接地址
     */
    private List<String> hostWithPorts;
    /**
     * 客户端超时时间单位是毫秒
     */
    private int connectionTimeout  = 5 * 60 * 1000;
    /**
     * 最大重试次数
     */
    private int maxAttempts = 6;
    /**
     * 最大连接数
     */
    private int maxTotal = 1000;
    /**
     * 最大空闲数
     */
    private int maxIdle = 200;
    /**
     * 最小空闲数
     */
    private int minIdle = 10;
    /**
     * 最大建立连接等待时间，单位是毫秒
     */
    private int maxWait = 1000;
    /**
     * 是否在从池中取出连接前进行检验,如果检验失败,则从池中去除连接并尝试取出另一个
     */
    private boolean testOnBorrow = true;

    public boolean isCache() {
        return cache;
    }

    public void setCache(boolean cache) {
        this.cache = cache;
    }

    public String getMode() {
        return mode;
    }

    public void setMode(String mode) {
        this.mode = mode;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public int getDatabase() {
        return database;
    }

    public void setDatabase(int database) {
        this.database = database;
    }

    public List<String> getHostWithPorts() {
        return hostWithPorts;
    }

    public void setHostWithPorts(List<String> hostWithPorts) {
        this.hostWithPorts = hostWithPorts;
    }

    public int getConnectionTimeout() {
        return connectionTimeout;
    }

    public void setConnectionTimeout(int connectionTimeout) {
        this.connectionTimeout = connectionTimeout;
    }

    public int getMaxAttempts() {
        return maxAttempts;
    }

    public void setMaxAttempts(int maxAttempts) {
        this.maxAttempts = maxAttempts;
    }

    public int getMaxTotal() {
        return maxTotal;
    }

    public void setMaxTotal(int maxTotal) {
        this.maxTotal = maxTotal;
    }

    public int getMaxIdle() {
        return maxIdle;
    }

    public void setMaxIdle(int maxIdle) {
        this.maxIdle = maxIdle;
    }

    public int getMinIdle() {
        return minIdle;
    }

    public void setMinIdle(int minIdle) {
        this.minIdle = minIdle;
    }

    public int getMaxWait() {
        return maxWait;
    }

    public void setMaxWait(int maxWait) {
        this.maxWait = maxWait;
    }

    public boolean isTestOnBorrow() {
        return testOnBorrow;
    }

    public void setTestOnBorrow(boolean testOnBorrow) {
        this.testOnBorrow = testOnBorrow;
    }
}
